#pragma once

namespace DXBase
{
	// MSDN http://msdn.microsoft.com/en-us/library/windows/desktop/ms679751
	// say that code range is free: 0x0200-0xFFFF
	public enum class ErrorCodes
	{
		CodeStart = 0x0200, CodeEnd = CodeStart + 100, NotErrorCode = CodeEnd - 1,

		ContextNotReady = CodeStart + 2,
		OverMaxConstantBufferIndex = CodeStart + 5,
		ContextDoNotMatch = CodeStart + 6,
		FixedSizeArray = CodeStart + 7,
		ArgumentOutOfRange = CodeStart + 8,
		ShapeNotInitialized = CodeStart + 9,
		ShapeVerticesBufferHaveDifferentSize = CodeStart + 10,
		ShaderEmpty = CodeStart + 11,
		ContextNotSet = CodeStart + 12,
		ContextNotRendering = CodeStart + 13,
		TextureEmpty = CodeStart + 14,
		TargetIsInUse= CodeStart + 15,
		Empty = CodeStart + 16,
		Closed = CodeStart + 17,
		CanOnlyResizeOwnedData = CodeStart + 18,
		ShapeDoNotHaveEnoughVertexBuffer = CodeStart + 19,
		ShapeStrideDoesntMatchVertexLayout = CodeStart + 20,
		DataTooSmall = CodeStart + 21,
	};

	// You can't throw custom exception with custom message across ABI
	// This will help throw custom Exception with known HRESULT value
	public ref class ExHelper sealed
	{
	public:
		static void Throw(ErrorCodes c);
		static ErrorCodes GetCode(Windows::Foundation::HResult ex);
		static Windows::Foundation::HResult CreateWinRTException(ErrorCodes c);

	internal:
		static Platform::Exception^ CreateException(ErrorCodes c);
		static ErrorCodes GetCode(Platform::Exception^ ex);

	private:
		ExHelper();
	};
}